﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace Big_Data.View
{
    public partial class FrmAreaChart : Form
    {
        DataBase userDB = new DataBase();

        public FrmAreaChart()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
        }

        private void FrmTimeChart_Load(object sender, EventArgs e)
        {
            // 设置曲线的样式
            Series series = chart1.Series[0];
            // 画样条曲线（Spline）
            series.ChartType = SeriesChartType.Column;
            // 线宽2个像素
            series.BorderWidth = 2;
            // 线的颜色：红色
            series.Color = System.Drawing.Color.Blue;
            // 图示上的文字
            series.LegendText = "区域安装统计";

            string sqlstr = "select e.Area_code,e.Area_Name, count(1) as totalcount "
               + " from T_assemble a"
                + " inner join S_station b on a.Sta_code=b.Sta_code "
                + " inner join S_area e on b.Area_code=e.Area_code ";//2
            sqlstr += " group by e.Area_code,e.Area_Name ";
            DataTable dataTable = userDB.show(sqlstr);

            // 在chart中显示数据
            int x = 0;
            foreach (DataRow v in dataTable.Rows)
            {
                series.Points.AddXY(v["Area_Name"], v["totalcount"]);
                x++;
            }

            // 设置显示范围
            ChartArea chartArea = chart1.ChartAreas[0];
            chartArea.AxisX.Minimum = 0;
            chartArea.AxisX.Maximum = 10;
            chartArea.AxisY.Minimum = 0d;
            chartArea.AxisY.Maximum = 100d;
        }
    }
}
